﻿using StudySystem.MainLogic.Items;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudySystem.SQLServer
{
    public static class DBForUser
    {
        /// <summary>
        /// 检查用户信息，正确则保存到当前对象
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool CheckID(string userID, string password,UserInformation user)
        {
            SqlParameter paraId = new SqlParameter("@userId", SqlDbType.NChar);
            paraId.Value = userID;
            SqlParameter paraPwd = new SqlParameter("@password", SqlDbType.NChar);
            paraPwd.Value = password;
            string sqlString = "select * from UserTable " +
                "where UserId = @userId and PassWord = @password";
            SqlDataReader dr = DbHelper.GetSafeDataReader(sqlString, paraId, paraPwd);
            if (dr.Read())
            {
                user.UserID = (string)dr["UserID"];
                user.UserName = (string)dr["UserName"];
                dr.Close();
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
